# Created by 黄景涛
# DATE: 2025/4/2


def happy_num(num: int):
    # 变量定义：cur_num(动态更新num)、hs_set
    hs_set = set()
    cur_num = num
    while cur_num != 1:
        # 更新cur_num
        cur_num = sum(int(bit)**2 for bit in str(cur_num))
        yield cur_num

        if cur_num not in hs_set:
            hs_set.add(cur_num)
        else:
            print('不是快乐数，退出')
            return False

    return True


if __name__ == '__main__':
    num1 = 19    # 快乐数
    gen = happy_num(num1)
    for i in gen:
        print(i)

    print('==================================')
    num2 = 18    # 非快乐数
    for i in happy_num(num2):
        print(i)
